﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using NetCoreCMS.Common;
using NetCoreCMS.IServices;
using NetCoreCMS.Models;

namespace NetCoreCMS.Web.Areas.Web.Controllers
{
    public class PointCenterController : UserController
    {
        public string action = string.Empty;
        public int page;         //当前页码
        public int totalcount;   //OUT数据总数
        public IBillsService _bills { get; set; }
        public IApplyService _apply { get; set; }
        public IActionResult Index()
        {
            action = Request.Query["act"];
            if (string.IsNullOrEmpty(action))
                action = "tixian";
            int.TryParse(Request.Query["page"], out page);
            page = page > 0 ? page : 1;
            ViewBag.action = action;
            string strwhere = "where user_id=" + GetUserInfo().id;
            ViewBag.billsList = new List<Bills>();
            ViewBag.applyList = new List<Apply>();
            switch (action)
            {
                case "bills":
                    {
                        var list = _bills.GetList(page, 50, strwhere, "add_time desc,id desc");
                        totalcount = _bills.RecordCount(strwhere);
                        string pageUrl = Utils.CombUrlTxt("/Web/PointCenter/Index", "page={0}&act={1}", "__id__", action);
                        ViewBag.pagelist = Utils.OutPageList(50, page, totalcount, pageUrl, 8);
                        ViewBag.billsList = list;
                    }
                    break;
                case "apply":
                    {
                        var list = _apply.GetList(page, 50, strwhere, "add_time desc,id desc");
                        totalcount = _apply.RecordCount(strwhere);
                        string pageUrl = Utils.CombUrlTxt("/Web/PointCenter/Index", "page={0}&act={1}", "__id__", action);
                        ViewBag.pagelist = Utils.OutPageList(50, page, totalcount, pageUrl, 8);
                        ViewBag.applyList = list;
                    }
                    break;
            }
            return View();
        }
    }
}